#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>

int main()
{
  printf("我是一个进程:%d\n",getpid());

  pid_t id = fork();
  if(id == 0)
  { 
    //执行另一个程序
    char *const argv[]={
      (char*)"othercmd",
      (char*)"-a",
      (char*)"-b",
      NULL
    };

    char* myenv[] = {
      "PATH=/home/zhangsan/linux/exec",
      NULL
    };

    extern char** environ;
    putenv((char*)"haha=aaaaaaaaaaaaaaaaaaa");
    execvpe("othercmd",argv,environ);//程序替换函数
    exit(3);
  }

  wait(NULL);
  printf("代码运行中....\n");
  printf("代码运行中....\n");
  printf("代码运行中....\n");
  printf("代码运行中....\n");
  printf("代码运行中....\n");
  printf("代码运行中....\n");

  return 0;
}
